/*************************************************************************
    > File Name: face_serialize.cpp
    > Author: fanzhihui
    > Mail: 953106194@qq.com 
    > Created Time: 2019年06月26日 星期三 15时58分18秒
 ************************************************************************/
#include<iostream>
#include "face_serialize.h"

using namespace std;

FileFaceSerialize::FileFaceSerialize(const string& file)
{
	filename = file;
}
	

FileFaceSerialize::~FileFaceSerialize()
{
	fIn.close();
	fOut.close();
}


void FileFaceSerialize::Serialize(const face_serial_info_t& face)
{

	if(!fOut.is_open()){
		fOut.open(filename,ios::app);
	}
	string line = face.Serialize();
	fOut << line << std::endl;
	fOut.flush();
}
	

void FileFaceSerialize::UnSerialize(vector<face_serial_info_t>& faces)
{

	fIn.open(filename, ios::in);
	string line;
	while(getline(fIn, line))
	{
		//std::cout << "--->" << line << std::endl;
		face_serial_info_t face_serial;
		
		if(line.empty()) continue;

		face_serial.UnSerialize(line);
		faces.push_back(face_serial);
	}
	fIn.close();
}


void FileFaceSerialize::Clear()
{
	if(fOut.is_open()){
		fOut.close();
	}

	fOut.open(filename,ios::trunc);
	fOut.close();
}


